<?php
class WephpController extends SmartyWe
{
	private $var = array();
	public function __construct(){
        //echo "测试";        
        if(C('SMARTY_ON')) {
            parent::__construct();
        }
        if(method_exists($this, '__init')){ //防止继承控制器中的构造方法覆盖 此构造方法，这样就能都使用得到 两个 构造方法
        	$this->__init();
        }

         if(method_exists($this, '__auto')){ //防止再次继承控制器中的构造方法覆盖 此构造方法，这样就能都使用得到 两个 构造方法
        	$this->__auto();
        }

	}


    /*操作成功跳转提示信息*/
	protected function success($msg=NULL,$url=NULL,$time=3){
		$url = $url ? "window.location.href='" .$url ."'" :'window.history.back(-1)';
		include APP_VIEW_PATH . '/success.html';
		die;
	}

	protected function error($msg=NULL,$url=NULL,$time=3){
         $url = $url ? "window.location.href='" .$url ."'" :'window.history.back(-1)';
		include APP_VIEW_PATH . '/error.html';
		die;
	}

    protected function get_tpl($tpl){
        
         if(is_null($tpl)){
            $path = APP_VIEW_PATH . '/' . CONTROLLER . '/' . ACTION . '.html';
            //echo "$path";
         } else {
            $suffix = strrchr($tpl, '.');
            $tpl = empty($suffix) ? $ptl . '.html' : $tpl;
            $path = APP_VIEW_PATH . '/' .CONTROLLER . '/' . $tpl;
         }
         return $path;
    }

	protected function fetch($tpl = NULL){
         $path = $this->get_tpl($tpl);

         if(!is_file($path)) echo $path . '模版文件不存在';
          
          if(C('SMARTY_ON')){
            parent::fetch($path);
        } else {
          extract($this->var);//把数组键值变为变量值
         //P($this->var);
         include $path;
        }  

	}

	protected function assign($var,$value){
       if(C('SMARTY_ON')){ 
            parent::assign($var,$value);
        } else {
            $this->var[$var] = $value;
        }  
	}
}



?>